#include<iostream>
#include<fstream>
#include<Windows.h>
#include"RWD.h"
#include"User.h"
#include"Element.h"
#include"Color.h"
#include"UsePage.h"
#include"startModule.h"
#include"WriteDatas.h"
#include"ReadUserData.h"
#include"registerInterface.h"
#include"PersonPageModule.h"
using namespace std;
//void getWords(string strs[][2], int N);

//判断是否在一个月内
bool judgeDay() {
	SYSTEMTIME sys;
	GetLocalTime(&sys);
	ifstream R_File;
	R_File.open("Day.txt", ios::in);
	if (!R_File) {
		WriteDay(ReadUserData());//修改Day的值
		return false;
	}
	else {

		int x;
		int time[2];
		for (int i = 0; i < 2; i++) {
				R_File >> x;
				time[i] = x;
		}
		if (sys.wMonth > time[0] && sys.wDay <= time[1]) {
			R_File.close();
			return true;
		}
		else if (sys.wMonth == time[0] && sys.wDay - time[1] <= 30) {
			R_File.close();
			return true;
		}
		else {
			WriteDay(ReadUserData());//修改Day的值
			return false;
		}
	}

}

//旧版获取词库词汇，读取txt文件

/*void getWords(string strs[][2], int N1) {
	char str[100];
	ifstream File;
	File.open("words.txt", ios::in);
	if (!File) {
		cout << "文件打开失败！" << endl;
	}
	else {
		for (int i = 0;i<3405; i++) {
			File.getline(str, 100);
			string word1;
			string word2;
			unsigned int j;
			for (j = 0; j < strlen(str); j++) {
				if (str[j] == ' ') break;
				word1 += str[j];
			}
			strs[i][0] = word1;
			for (; j < strlen(str)&&j<100; j++) {
				word2 += str[j];
			}
			strs[i][1] = word2;
		}
	}
}*/

//提示语(未完成)
void reminder(int choose) {
	switch (choose) {
	case 0:cout << left << "";
	}
}

//控制使用界面
void controlUsePage(User& U) {
	int* p;
	int arr[4] = { 0,1,2,3};
	p = arr;
	while (1) {
		drawInterface(U, *p);
		char a;
		cout << setw(50) << "Tab键打开或关闭个人主页...";
		a = _getch();
		while (a != VK_RETURN && a != VK_TAB) {
			
			if (a == 'w' && *p != 0) {
				p--;
				system("cls");
				drawInterface(U, *p);
			}
			if (a == 's' && *p != 1) {
				p++;
				system("cls");
				drawInterface(U, *p);
				
			}
			cout << setw(50) << "Tab键打开或关闭个人主页...";
			a = _getch();	
		}
		system("cls");
		if (a == VK_TAB) {
			controlPersonPage(U, arr);
			continue;
		}
		if (*p == 0) {
			RWD(U);
			system("cls");
		}
		else {

			WriteUserData(U);
			Element::drawStruct();
			cout << setw(32) << "欢迎下次使用...";
			break;
		}

	}
}


//主函数
int main(){
	system("mode con cols=50 lines=40");	//控制控制台的显示大小
	//drawlog_in();
	if(!judgeDay())
		controlStartMenu();
	drawLoading();
	User U(ReadUserData());
	system("cls");
	controlUsePage(U);
	
	return 0;
}